﻿using com.iot.core.exception;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace com.iot.core.util
{
    public class ValidatorUtils
    {
        public static void validateEntity(object Entity)
        {
            var validationContext = new ValidationContext( Entity);
            Validator.ValidateObject( Entity, validationContext);


            var validationResults = new List<ValidationResult>();

            var succcess = Validator.TryValidateObject( Entity, validationContext, validationResults, true);
            if (!succcess)
            {
                var msg = string.Join("\n", validationResults.Select(r => r.ErrorMessage)); ;
                throw new MyException(ExceptionEnum.PInError,msg); 
            }
        }
         

    }
}
